'''
$LastChangedBy: csgillespie $
$LastChangedDate: 2007-06-06 11:08:06 +0000 (Wed, 06 Jun 2007) $
Class is currently a bit empty.
In the furture will add automatic plotting
and stuff
'''

from tempfile import NamedTemporaryFile
try:
	import gillespie2
except ImportError:
	print '##################################################'
	print 'The module gillespie2 is not installed.'
	print 'This means you cannot acccess the Gillespie stochastic simulator'
	print 'The module is available from www.basis.ncl.ac.uk'
	print '##################################################'


class Gillespie:
	'''Calls the Gillespie simulator'''
	def __init__(self, sbml_string):
		self.data = {}
		self.sbml = sbml_string
	
	def gillespie(self, max_time, num_steps, seed):
		'''Calls the simulator'''
		temp_file = NamedTemporaryFile()
		gillespie2.pythonSimulate(self.sbml, max_time, \
			 num_steps, seed, temp_file.name)
		
		species_names = temp_file.readline().strip().split(' ')
		for sp in species_names:
			self.data[sp] = []

		for line in temp_file:
			for data, sp in zip(line.strip().split(' '), species_names):
				self.data[sp].append(data)
	
	
	def getData(self):
		'''Returns the data attribute'''
		return self.data
		
		
